package weaver.sscan.control;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import weaver.sscan.bean.JavaIssues;
import weaver.sscan.redis.RedisUtil;
import weaver.sscan.service.IssuesService;
import weaver.sscan.service.SscanServices;
import weaver.sscan.service.SyncMemService;

@RestController
public class ScanControl {

    @Autowired
    SscanServices sscanServices;

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    SyncMemService syncMemService;

    @Autowired
    IssuesService issuesService;

    @GetMapping("/scan")
    public String scan() {

        Long start = System.currentTimeMillis();
        JSONObject result = new JSONObject();

        sscanServices.sycnCode();
        sscanServices.scanJava();
        sscanServices.scanJsp();
        sscanServices.scanWEB();
        sscanServices.sacnSql();
        syncMemService.syncMems();
        issuesService.updateIssuesMen();
        sscanServices.transitionView();
        Long end = System.currentTimeMillis();
        result.put("status", "200");
        result.put("time", (end - start) / 1000 / 60 + "s");

        return result.toString();
    }


    @GetMapping("/syncMen")
    public String syncMen() {

        JSONObject result = new JSONObject();
        Long start = System.currentTimeMillis();
        result.put("status", "200");
        syncMemService.syncMems();
        Long end = System.currentTimeMillis();
        result.put("time", (end - start) / 1000 / 60 + "s");

        return result.toString();
    }

    @GetMapping("/redisTest")
    public String redisTest() {

        JSONObject result = new JSONObject();
        result.put("status", "200");
        JavaIssues javaIssues = new JavaIssues("", "123123123", "123123123", 123, "123123123");
        redisUtil.set("" + System.currentTimeMillis(), javaIssuess);
        BaseBean bb = new BaseBean();
        bb.writeLog("FnaElecInvoiceLockNew-sql1:", "1111");
        System.out.println("1111");
        System.out.error(1111);
        logger.debugger("111");

        return result.toString();
    }

    @GetMapping("/redisGet")
    public String redisGet() {

        JSONObject result = new JSONObject();
        result.put("status", "200");
        JavaIssues ji = (JavaIssues) redisUtil.get("1581059687645");
        result.put("ji", ji.toString());

        return result.toString();
    }
}
